package com.wolf.controller;

import com.wolf.pojo.Wl_user;
import com.wolf.service.Wl_userService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import com.wolf.pojo.Wl_user;

import java.util.List;

@Controller
public class Wl_userController {
    @Autowired
    private Wl_userService wl_userService;

    @ModelAttribute
    Wl_user setwluserObject() {
        return new Wl_user();
    }

    /**
     * 查询用户管理所有
     */
    @RequestMapping("wl_user_get")
    public String get(ModelMap modelMap){
        List<Wl_user> list = wl_userService.getAll();
        modelMap.addAttribute("wl_user_list",list);
        return "table_data_tables";
    }


    /**
     * 修改
     */
    @ResponseBody
    @RequestMapping(value = "wl_user_modify", method = RequestMethod.POST)
    public String userUpdata (Wl_user wluserObject)
    {
        boolean rel = 1==wl_userService.updateByPrimaryKeySelective(wluserObject);
        return rel+"";
    }
    @RequestMapping(value = "wl_user_getById" ,method = RequestMethod.GET)
    public String getWlUserObject(Model model ,String userPrimaryKey)
    {
        Wl_user rel =wl_userService.selectByPrimaryKey(userPrimaryKey);
        model.addAttribute("wluserObject",rel);
        return "tabs_panels";
    }

    /**
     * 删除
     */
    @RequestMapping("wl_user_remove")
    public String remove(String userPrimaryKey){
        wl_userService.deleteByPrimaryKey(userPrimaryKey);
        return "redirect:wl_user_get";
    }

    /**
     * Wl_user表：用户新增
     * @param wl_user
     * @param model
     * @return
     */
    @RequestMapping("wl_user_Insert")
    public String Wl_user_Insert(Wl_user wl_user,Model model){
        System.out.println(wl_user.getUsername());
        //调用insertSelective方法：选择性新增
        int i = wl_userService.insertSelective(wl_user);

        if(i>0){
            System.out.println("新增成功");
        }

        return "redirect:/wl_user_get";
    }
}
